//
//  TabbarViewController.m
//  FoodList
//
//  Created by 王金晶 on 16/4/6.
//  Copyright © 2016年 王金晶. All rights reserved.
//

#import "TabbarViewController.h"
#import "TodayViewController.h"
#import "FindViewController.h"
#import "HealthViewController.h"
#import "FoodVideoViewController.h"
#import "BaseViewController.h"
@interface TabbarViewController ()<UITabBarControllerDelegate,baseViewControllerDelegate,rightDelegate>

@end

@implementation TabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
   _rightVc = [[RightViewController alloc]initWithNibName:@"RightViewController" bundle:nil];
    _rightVc.delegate = self;
    [self.view addSubview:_rightVc.view];
    [self addChildViewController:_rightVc];
    
    //_tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    
    TodayViewController *todayViewVc = [[TodayViewController alloc]initWithNibName:@"TodayViewController" bundle:nil];
    UINavigationController *todayNav = [[UINavigationController alloc]initWithRootViewController:todayViewVc];
    todayViewVc.rightVc = _rightVc;
    todayViewVc.delegate = self;
    todayNav.tabBarItem.title = @"今日";
    todayNav.tabBarItem.image = [UIImage imageNamed:@"today"];
    
    FindViewController *findViewVc = [[FindViewController alloc]initWithNibName:@"FindViewController" bundle:nil];
    UINavigationController *findNav = [[UINavigationController alloc]initWithRootViewController:findViewVc];
    findViewVc.rightVc = _rightVc;
    findViewVc.delegate = self;
    findNav.tabBarItem.title = @"发现";
    findNav.tabBarItem.image = [UIImage imageNamed:@"find"];

    
    FoodVideoViewController *foodViewVc = [[FoodVideoViewController alloc]initWithNibName:@"FoodVideoViewController" bundle:nil];
    UINavigationController *foodNav = [[UINavigationController alloc]initWithRootViewController:foodViewVc];
    foodViewVc.rightVc = _rightVc;
    foodViewVc.delegate = self;
    foodNav.tabBarItem.title = @"食趣";
    foodNav.tabBarItem.image = [UIImage imageNamed:@"foodvideo"];

    
    
    HealthViewController *healthViewVc = [[HealthViewController alloc]initWithNibName:@"HealthViewController" bundle:nil];
    UINavigationController *healthNav = [[UINavigationController alloc]initWithRootViewController:healthViewVc];
    healthViewVc.rightVc = _rightVc;
    healthViewVc.delegate = self;
    healthNav.tabBarItem.title = @"养生";
    healthNav.tabBarItem.image = [UIImage imageNamed:@"health"];

    
    
    self.viewControllers = @[todayNav,findNav,foodNav,healthNav];
    self.delegate = self;
    
    //设置所有导航栏的颜色
    [[UINavigationBar appearance]setBarTintColor:MyColour];
    
    
    
    
}
- (void)changerightFrame {
    if (_rightVc.view.frame.origin.x == 0) {
        return;
    }
    [UIView animateWithDuration:0.15 animations:^{
        _rightVc.view.frame = CGRectMake(0, 0, 280, Height);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 animations:^{
            _rightVc.view.frame = CGRectMake(-10, 0, 280, Height);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.3 animations:^{
                _rightVc.view.frame = CGRectMake(0, 0, 280, Height);
            }];
        }];
    }];
    self.tabBar.userInteractionEnabled = NO;
    for (UINavigationController *nav in self.viewControllers) {
        for (UIViewController *Vc in nav.childViewControllers) {
            Vc.view.userInteractionEnabled = NO;
        }
    }
    
}
- (void)close
{
    self.tabBar.userInteractionEnabled = YES;
    for (UINavigationController *nav in self.viewControllers) {
        for (UIViewController *Vc in nav.childViewControllers) {
            Vc.view.userInteractionEnabled = YES;
        }
    }
}
/*
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    if (_rightVc.view.frame.origin.x == -206) {
        return;
    }
    [UIView animateWithDuration:0.15 animations:^{
        _rightVc.view.frame = CGRectMake(-241 + 35, 0, 280, Height);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 animations:^{
            _rightVc.view.frame = CGRectMake(-241 + 30, 50, 280, Height);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.3 animations:^{
                _rightVc.view.frame = CGRectMake(-241 - 50 , 200, 280, Height);
            }];
        }];
    }];
    self.tabBar.userInteractionEnabled = YES;
    for (UINavigationController *nav in self.viewControllers) {
        for (UIViewController *Vc in nav.childViewControllers) {
            Vc.view.userInteractionEnabled = YES;
        }
    }
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
